package cn.senjoeson.healthsport.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.senjoeson.healthsport.GreenDaoManager;
import cn.senjoeson.healthsport.R;
import cn.senjoeson.healthsport.bean.User;
import cn.senjoeson.healthsport.dao.UserDao;
import cn.senjoeson.healthsport.utils.SPUtils;

/**
 * Created by senjoeson on 2018/5/26.
 */

public class MeFragment extends Fragment {


    @BindView(R.id.username)
    TextView mUsername;
    @BindView(R.id.realname)
    TextView mRealname;
    @BindView(R.id.gender)
    TextView mGender;
    Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_my_info, container, false);
        unbinder = ButterKnife.bind(this, view);
        long userid = Long.parseLong(SPUtils.getString("userid", ""));
        UserDao userDao = GreenDaoManager.getInstance().getNewSession().getUserDao();
        List<User> users = userDao.queryRaw("where _id= ?", String.valueOf(userid));
        User user = users.get(0);
        mUsername.setText(user.getUsername());
        mGender.setText(user.getGender());
        mRealname.setText(user.getRealname());
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
